#include "mainwindow.h"

#include <QApplication>
#include <QFile>
#include <QDebug>
#include <QString>
#include <QDir>
#include "global.h"
#include <QSettings>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    //读取qss文件的内容
    QFile qss(":/style/stylesheet.qss");
    if(qss.open(QIODeviceBase::ReadOnly))
    {
        qDebug()<<"open success\n";
        QString style = QLatin1String(qss.readAll());
        //设置全局qss样式
        a.setStyleSheet(style);
        qss.close();

    }
    else
    {
        qDebug()<<"Open failed\n";
        return -1;
    }

    QString fileName = "config.ini";
    //获取应用最后的执行文件的目录
    QString app_path=QCoreApplication::applicationDirPath();
    QString config_path = QDir::toNativeSeparators(app_path +QDir::separator()+fileName);

    QSettings settings(config_path, QSettings::IniFormat);
    QString gate_host = settings.value("GateServer/host").toString();
    QString gate_port = settings.value("GateServer/port").toString();
    qDebug()<<"host = "<<gate_host<<"   port= "<<gate_port<<Qt::endl;
    gate_url_prefix = "http://"+gate_host+":"+gate_port;


    MainWindow w;
    w.show();

    //开始事件循环
    return a.exec();
}
